package com.wlc.thread.threadpool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description ThreadPool线程池
 * @date 2021-09-19 14:25
 */
public class ThreadPoolDemo {

    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2, 60L,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(4));
        for (int i = 0; i < 6; i++) {
            TaskThred taskThred = new TaskThred("任务"+i);
            executor.execute(taskThred);
        }
        executor.shutdown();
    }

}
class TaskThred implements Runnable {
    private String taskName;
    public TaskThred(String taskName) {
        this.taskName = taskName;
    }
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + taskName);
    }
}
